/*
	Copyright (C) 2010 Salil Bhagurkar

	This file is part of k3

	k3 is free software: you can redistribute it and/or modify
	it under the terms of the GNU Lesser General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	k3 is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU Lesser General Public License for more details.

	You should have received a copy of the GNU Lesser General Public License
	along with k3.  If not, see <http://www.gnu.org/licenses/>.
*/

#include <shared.h>

/**
This presents the printk as a device for user mode applications
This does not register a driver, since this device does not go down or come back up again. This is always there
and is supported by the architecture as the debugging method
*/

static int printk_write(struct fs *referrer, struct fs *this, struct buffer *buf, u32 offset, u32 count)
{
	u32 i = 0;
	while(count--) {
		printk("%c", *(char *)(buf->data + i));
		i++;
	}
	return 0;
}


/**
Memory hex display device
*/

static int printmem_write(struct fs *referrer, struct fs *this, struct buffer *buf, u32 offset, u32 count)
{
	printmem(buf->data, count);
	return 0;
}

int register_printk_dev()
{
	struct fs *printk_dev = fs_create(FSFLAGS_DEVICE, "printk");
	printk_dev->system = fs_create_system(0, dummy, printk_write, dummy, printk_dev);
	fs_link(fsparse_get("/devices"), printk_dev);
	struct fs *printmem_dev = fs_create(FSFLAGS_DEVICE, "printmem");
	printmem_dev->system = fs_create_system(0, dummy, printmem_write, dummy, printmem_dev);
	fs_link(fsparse_get("/devices"), printmem_dev);
	return 0;
}
